﻿// Generic 3-D object class for sprites in the ProjectionContainer

class com.spikything.gfx3d.Sprite extends MovieClip {

	var c				:Color;		// Colour transform
	var x				:Number;	// X position
	var y				:Number;	// Y position
	var z				:Number;	// Z position
	var vx				:Number;	// X speed
	var vy				:Number;	// Y speed
	var vz				:Number;	// Z speed
	var wrapMode		:Boolean;	// Does this sprite 'wrap' off the screen edge?
	var selfLighting	:Object;	// Self illumination RGB components
	var isVisible		:Boolean;	// Visibility of sprite in 3-D viewport
	var spriteType		:String;	// Optional identifier used for iteration

	function Sprite () {
		c = new Color(this);
		selfLighting = {r:0, g:0, b:0};
		vx = 0;
		vy = 0;
		vz = 0;
		isVisible = true;
	}

	public function update ():Void {
		x += vx;
		y += vy;
		z += vz;
		if (wrapMode) {
			while (_parent.z+z<0) 				z += _parent.maxDist;
			while (_parent.z+z>_parent.maxDist) z -= _parent.maxDist;
			while (_parent.x+x>1500) 			x -= 3000;
			while (_parent.x+x<-1500) 			x += 3000;
		}
	}

	public function impulse (ix:Number, iy:Number, iz:Number):Void {
		vx += ix;
		vy += iy;
		vz += iz;
	}

	public function setVelocities (ix:Number, iy:Number, iz:Number):Void {
		vx = ix;
		vy = iy;
		vz = iz;
	}

	public function setPos (ix:Number, iy:Number, iz:Number):Void {
		x = ix;
		y = iy;
		z = iz;
	}

	public function getSelfLighting (channel:String):Number {
		return selfLighting[channel];
	}
}